﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" href="/style/login.css">
    <link href="/script/pack/zui/css/zui.min.css" rel="stylesheet" />
    <script src="script/config.js"></script>
</head>

<body>
    <div class="login">

    </div>
</body>
</html>
<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>

<script type="text/html" id="login-tem">
    <div class="myapp-login-logo-text">
        <div class="myapp-login-logo-text">
            MY-Plus<span> Login</span> <i class="am-icon-skyatlas"></i>

        </div>
    </div>
    <div class="input-control has-icon-left">
        <input class="form-control account" data-form="Account" value="{{Account}}" id="inputAccountExample1" autofocus type="text" placeholder="用户名" maxlength="16" />
        <label for="inputAccountExample1" class="input-control-icon-left"><i class="icon icon-user "></i></label>
    </div>

    <div class="input-control has-icon-left">
        <label for="inputPasswordExample1" class="input-control-icon-left"><i class="icon icon-key"></i></label>
        <input id="inputPasswordExample1" data-form="Pwd" value="{{Pwd}}" class="form-control pwd" autofocus type="password" placeholder="密码" maxlength="16" />
    </div>
    <button class="btn btn-block" id="btn-submit" type="button">登 录</button>

</script>
<script>
    $(function () {
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "Account",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "Pwd",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },

            ];
            formValidEvent = $(".login").formValid(formValidData);
        }
        var inintData = {
            Account: "",
            Pwd: "",
        };

        $(".login").templateRender({ el: "login-tem", data: inintData });//渲染模板，要先渲染才能获值
       
        $(window).keydown(function (e) {
            formValidInit();
            if (e.keyCode == 13) {
                if (!formValidEvent.check()) { return; }
                if ($("#inputAccountExample1").val() == "" || $("#inputPasswordExample1").val() == "") {
                    new $.zui.Messager('提示消息：请正确输入！', {
                        type: 'warning' // 定义颜色主题
                    }).show();
                    return
                }
                SubmitLogin();
            }
        });
        $(".login").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            formValidInit();
            if (!formValidEvent.check()) { return; }
            SubmitLogin();
        });
    });
    //提交登录请求
    function SubmitLogin() {
        var apiUrl = "user/login"; 
        $(".login").ajaxFormSubmit(apiUrl, {
            pass: function (d) {
                $.msgSucceed(d.Errmsg);
                $.cookie("o_autn_token", d.Token, {
                    expires: 10
                });
                $.cookie("RealName", d.RealName);
                window.location.href = "/home.html"
                return
            },
            error: function (d) {
                $.msgFall(d.Errmsg);
            }
        })
        return
    }
</script>
